
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

//using Db4objects;
namespace NCS_CS
{
	internal class DemoDbNew
	{
        int id;
        int[] xid;
		int xidn;
        Sig s1;
		int count;
		private void getids()
		{
            Db4objects.Db4o.IObjectContainer db = null;
            db = Db4objects.Db4o.Db4oFactory.OpenFile(modLog.initpath + "\\demo.data");
            Db4objects.Db4o.Query.IQuery query = db.Query();
			query.Constrain(typeof(Sig));
            Db4objects.Db4o.IObjectSet o = null;
			o = query.Execute();
			if (o.Count > 0) {
				xidn = o.Count;
				 // ERROR: Not supported in C#: ReDimStatement
                xid =new int[xidn];
				int i = 0;
				i = 0;
				foreach (Sig one in o) {
					xid[i] = one.sampleid;
					i = i + 1;
				}
			} else {
				xidn = 0;
			}
			db.Close();
		}

		public DemoDbNew() : base()
		{

		}
		public int getId()
		{
			int a = 0;
            System.Random r = new System.Random();
			a = 0 + Convert.ToInt32(r.NextDouble() * (xidn - 1));
			return xid[a];
			//239 to 267
		}
		public void startit()
		{
            try
            {
                getids();
                id = getId();
                s1 = new Sig();
                ModMain.loadsignew(ref s1, id);
                count = 0;
                return;
            }
            catch (System.Exception e)
            {
                modLog.savelogmsg("start it");
                modLog.savelogmsg(e.ToString());
            }
		}




		public double getchanelVolt(string ele)
		{
			if (count < s1.xn) {
				return s1.getPoint(ModMain.getEleChanel(ele), count);
			} else {
				return 0;
			}

		}
		public void @add()
		{
			count = count + 10;
		}

	}
}
